package com.oa.modules.approvalsec1.controller;

import java.util.Arrays;
import java.util.Map;
import java.util.Date;
import com.oa.common.utils.AppUtils;
import com.oa.modules.sys.controller.AbstractController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.oa.modules.approvalsec1.entity.CloudVideoEntity;
import com.oa.modules.approvalsec1.service.CloudVideoService;
import com.oa.common.utils.PageUtils;
import com.oa.common.utils.R;



/**
 * 云探勘表
 *
 * @author jiangwei
 * @email 785297226@qq.com
 * @date 2021-09-27 14:54:04
 */
@RestController
@RequestMapping("cloud/video")
@Api(tags = "云探勘视频相关接口")
public class CloudVideoController extends AbstractController {
    @Autowired
    private CloudVideoService cloudVideoService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "列表")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = cloudVideoService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApiOperation(value = "信息")
    public R info(@PathVariable("id") String id){
		CloudVideoEntity cloudVideo = cloudVideoService.getById(id);
        return R.ok().put("cloudVideo", cloudVideo);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation(value = "保存")
    public R save(@RequestBody CloudVideoEntity cloudVideo){
       if(StringUtils.hasText(cloudVideo.getResultUrl())&& cloudVideo.getResultUrl().contains(",")){
           String[] split = cloudVideo.getResultUrl().split(",");
           for (String resultUrl : split) {
               cloudVideo.setId(AppUtils.getUUID());
               cloudVideo.setCreateDate(new Date());
               cloudVideo.setCreateOper(getUserId().toString());
               cloudVideo.setResultUrl(resultUrl);
               cloudVideoService.save(cloudVideo);
           }
       }else {
           cloudVideo.setId(AppUtils.getUUID());
           cloudVideo.setCreateDate(new Date());
           cloudVideo.setCreateOper(getUserId().toString());
           cloudVideoService.save(cloudVideo);
       }
        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改")
    public R update(@RequestBody CloudVideoEntity cloudVideo){
        cloudVideo.setUpdateDate(new Date());
        cloudVideo.setUpdateOper(getUserId().toString());
		cloudVideoService.updateById(cloudVideo);
        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @ApiOperation(value = "删除")
    public R delete(@RequestBody String[] ids){
		cloudVideoService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
